<template>
		<modal-container v-el:modal title="编辑" class="edit-modal">
		<form v-el:submitform @submit.prevent> 
			<div>
				<table class="table table-hover">
					<tbody>
							<tr>
								<td>素材ID</td>
								<td>
									<input type="text" class="form-control" :value="model.media" disabled  name="media">
								</td>
							</tr>						
							<tr>
								<td>商户编号</td>
								<td>
									<input type="text" class="form-control" :value="model.mchtId" disabled  name="mchtId">
								</td>
							</tr>
							<tr>
								<td>名称</td>
								<td>
								  <input type="text" class="form-control" :value="model.name"  name="name">				
								</td>
							</tr>
							<tr>
								<td>描述</td>
								<td>
								  <input type="text" class="form-control" :value="model.dsc"  name="dsc">				
								</td>
							</tr>																								
														 		
					</tbody>
				</table>
			</div>
			<div class="modal-footer">
				<v-button type="submit" theme="primary" class="pull-left">确认</v-button>
				<v-button @click="hide">取消</v-button>
			</div>
		</form>
		</modal-container>	

</template>

<script>
	
	let serialize = require('form-serialize');
	 
	export default {
		props: {
			model: {
			  type: Object
			}			
		},
		data:()=>({
		
		}),
		methods: {
			  init() {
					$(this.$els.modal).modal("show");
				},
		  	hide() {
					$(this.$els.modal).modal("hide");
				},
		    reload() {
					this.$dispatch("table-reload");
				},					
				submit(data) {
					let self = this;
					
					self.$post({
						url: "/api/v1" + projectName_Url + "/wechat/media/upd.html",
						data
					}).then(response => {
						let data = {
							title: "操作提示",
							content: "编辑操作成功"
						}
						Midway.alert(data);
						self.hide();
						self.reload();
					}, response => {

					});					
				}
	 },
	 ready() {
		 
		let self = this;		 
		$(this.$els.submitform).submit(function () {
			return false;
		});				
		 $(self.$els.submitform).validate({
			 submitHandler() {
					let form = this.currentForm;	
				 
					$(form).find("input").each(function () {
						$(this).val($.trim($(this).val()));
					});				 
				 
					let _data = serialize(form, {
							hash: true,
						  disabled: true,
						  empty: true
					});					 				
				  self.submit(_data);				 				 
			 },
				rules: {
					name: {
						required: true
					}				
				},
				messages: {
					name: {
						required: "名称为必填项"
					}				
				}			 
		 });
	 }
}
</script>